<?php  
session_start();
include("connect.php");
if ($_GET['action'] == 'login')
{
include("connect.php");
$username=$_POST['username'];
$pwd=$_POST['pwd'];
$sql=mysqli_query($conn,"select * from userinfo where username='".$username."' and pwd='".$pwd."'");
$info=mysqli_fetch_array($sql);
if($info==true)
{

$_SESSION['username']=$username; 
 
   echo "<script>alert('恭喜，登录成功!');window.location='index.php';</script>";
   exit;
}
else
{ 
  echo "<script>alert('用户名或者密码错误!');window.location='index.php';</script>";
}
}
?>
				<?php
		if($_SESSION['username']=="admin"){
			session_start();
			session_unset();
			session_destroy();
			echo "<script>alert('后台已有账号登录，系统自动下线后台账号!');window.location='index.php';</script>";
		}
		 
		 ?>		
		 
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title></title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
		 crossorigin="anonymous"></script>
		<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
		 crossorigin="anonymous"></script>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
		 crossorigin="anonymous">
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
		 crossorigin="anonymous"></script>
	</head>
	<body>
		<div>
			<nav class="navbar navbar-expand-lg navbar-light bg-light">
				<a class="navbar-brand" href="index.php">寻书网</a>
				<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
				 aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
					<span class="navbar-toggler-icon"></span>
				</button>
				<div class="collapse navbar-collapse" id="navbarSupportedContent">
					<ul class="navbar-nav mr-auto">
						<?php
		if($_SESSION['username']=="")
		 {
		 ?>
						<li class="nav-item active">
							<a class="nav-link" data-toggle="modal" data-target="#exampleModal">登录 <span class="sr-only">(current)</span></a>
						</li>
						<li class="nav-item">
							<a class="nav-link" href="UserReg.php">注册</a>
						</li>
						<?php	
	}
	else
	{?>
						<li class="nav-item dropdown">
							<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
							 aria-haspopup="true" aria-expanded="false">
								功能
							</a>
							<div class="dropdown-menu" aria-labelledby="navbarDropdown">
								<a class="dropdown-item" href="SubmitBook.php">上传书籍</a>
								<a class="dropdown-item" href="MyBook.php">已上传的书籍</a>
								<a class="dropdown-item" href="Userinfo.php">修改个人信息</a>
								<div class="dropdown-divider"></div>
								<a class="dropdown-item" href="javascript:;">您好！
									<?php echo $_SESSION['username']?></a>
							</div>
						</li>
						<li class="nav-item">
							<a class="nav-link " href="out.php">退出</a>
						</li>
						<?php
	  }?>
					</ul>
				</div>
			</nav>
		</div>
		<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <h5 class="modal-title" id="exampleModalLabel">登录</h5>
		      </div>
		      <div class="modal-body">
		        <form method="post" name="login" action="header.php?action=login">
		          <div class="form-group">
		            <label for="recipient-name" class="col-form-label">用户名：</label>
		            <input type="text" name="username" required="required" autocomplete="off" placeholder="请输入用户名" class="form-control" >
		          </div>
		          <div class="form-group">
		            <label for="message-text" class="col-form-label">密码</label>
		            <input type="password" name="pwd" required="required" autocomplete="off" placeholder="请输入密码" class="form-control" >
		          </div>
				  <div class="form-group">
				  	<input type="submit" value="登录" class="btn btn-info" /> 
				  </div>
		        </form>
		      </div>
		      <div class="modal-footer">
		             <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
		           </div>
		    </div>
		  </div>
		</div>
	

